| 1 | const std = @import("std"); |
| 2 | |
| 3 | pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { |
| 4 | _ = stack_trace; |
| 5 | if (std.mem.eql(u8, message, "access of union field 'float' while field 'int' is active")) { |
| 6 | std.process.exit(0); |
| 7 | } |
| 8 | std.process.exit(1); |
| 9 | } |
| 10 | |
| 11 | const Foo = union { |
| 12 | float: f32, |
| 13 | int: u32, |
| 14 | }; |
| 15 | |
| 16 | pub fn main() !void { |
| 17 | var f = Foo{ .int = 42 }; |
| 18 | bar(&f); |
| 19 | return error.TestFailed; |
| 20 | } |
| 21 | |
| 22 | fn bar(f: *Foo) void { |
| 23 | f.float = 12.34; |
| 24 | } |
| 25 | // run |
| 26 | // backend=selfhosted,llvm |
| 27 | // target=x86_64-linux,wasm32-wasi |